<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%! String setstrnams = "0";  %>
<%
	String flmz = request.getParameter("csflname");
	String flmzs = request.getParameter("csflnames");
	System.out.println("###################");
	System.out.println("flname:" + flmz);
	System.out.println("flnames:" + flmzs);
	System.out.println("###################");

	try {
		Class.forName("com.mysql.jdbc.Driver").newInstance();
	} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
		e.printStackTrace();
	}
	Connection conns;
	try {
		conns = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
		Statement stmts = conns.createStatement();
		String sqls = "select type_name from blog_type where id = " + flmz;
		ResultSet rss = stmts.executeQuery(sqls);
		while (rss.next()) {
			String getstrs = rss.getString("type_name");
			setstrnams = getstrs;
		}
		rss.close();
		stmts.close();
		conns.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
%>
<title><%=setstrnams%>分类</title>
<style type="text/css">
body {
	text-align: center;
}

a {
	text-decoration: none;
	color: black;
}
a:hover {
    color: red;
}
.ljyd {
	position: absolute;
	left: 770px;
	top: 30px;
}
.ljydzy {
	position: absolute;
	left: 800px;
	top: 30px;
}
.biaotiyd {
    position: absolute;
	left: 500px;
	top: 20px;
}
table {
    position: relative;
	left: 80px;
	top: 110px;
}
table tr th{
    height: 70px;
}
.idkdxg{
    width: 70px;
}
.bkkdxg{
    width: 700px;
}
.sbwz{
    position: absolute;
	left: 0px;
	top: 0px;
}
.szwz{
    position: absolute;
	left: 100px;
	top: 0px;
}
</style>
</head>
<body onmousemove="pos()">
    <%
		String strSessionj = (String) request.getSession().getAttribute("namet");
		System.out.println("typelist:" + strSessionj);
		if(strSessionj == null){
			response.getWriter().append("<a href='http://localhost:8089/user_login.html' class='ljyd'>登录</a>");
			response.getWriter().append("<span class='ljydzy'><a href='mainpage.jsp'>&nbsp;&nbsp;&nbsp;返回主页</a></span>");	
		} else {
			response.getWriter().append("<a href='http://localhost:8089/user_personalpage.jsp' class='ljyd'>");
			response.getWriter().append(strSessionj);
			response.getWriter().append("</a>");
			response.getWriter().append("<span class='ljydzy'><a href='mainpage_login.jsp'>返回主页</a></span>");	
		}
	%>
	<!--  
	<a href="http://localhost:8089/user_personalpage.jsp" class="ljyd"><%=strSessionj%></a>
	<span><a href="mainpage_login.jsp" class="ljydzy">返回主页</a></span>
	-->
	<h1 class="biaotiyd"><%=setstrnams%>分类</h1>
	<%!
	    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	    private static final String DB_USER = "root";
	    private static final String DB_PWD = "ZLWL";
	    int csnumber = 0;
	%>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection conn;
		try {
			conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			Statement stmt = conn.createStatement();
			String sqlw = "select count(id) total from blog where type_id = " + flmz;
			ResultSet rsw = stmt.executeQuery(sqlw);
			System.out.println("blog_number1:" + rsw);
			int setnumb = 0;
			while (rsw.next()) {
				int getnumb = rsw.getInt("total");
				int getnumbs = rsw.getInt(1);
				System.out.println("blog_number1_getnumb:" + getnumb);
				System.out.println("blog_number1_getnumbs:" + getnumbs);
				setnumb = getnumb;
			}
			System.out.println("blog_number1:" + setnumb);
			System.out.println("****************************************");
			String sqlr = "select id from blog where type_id = " + flmz + " order by id limit 1";
			ResultSet rsr = stmt.executeQuery(sqlr);
			int setfirstid = 0;
			while (rsr.next()) {
				int getfirstid = rsr.getInt(1);
				setfirstid = getfirstid;
			}
			System.out.println("****************************************");
			String sqlv = "select id from blog where type_id = " + flmz;
			ResultSet rsv = stmt.executeQuery(sqlv);
			System.out.println("blog_list_number2:" + rsv);
			Map<String, String> hashMap3 = new HashMap<String, String>();
			int i = setfirstid;
			while (rsv.next()) {
			    hashMap3.put("id" + i, rsv.getString("id"));
			    System.out.println(hashMap3.get("id" + i));
			    i ++;
			}
			System.out.println("****************************************");
			String sqlu = "select title from blog where type_id = " + flmz;
			ResultSet rsu = stmt.executeQuery(sqlu);
			System.out.println("blog_list_number3:" + rsu);
			Map<String, String> hashMap4 = new HashMap<String, String>();
			int j = setfirstid;
			while (rsu.next()) {
			    hashMap4.put("title" + j, rsu.getString("title"));             
			    System.out.println(hashMap4.get("title" + j));
			    j ++;
			}
			System.out.println("****************************************");
			response.getWriter().append("<table border='1' id='cs'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th class='idkdxg'>ID</th>");
			response.getWriter().append("<th class='bkkdxg'>博客</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			int k = setfirstid;
			while(k < (setnumb + setfirstid)) {
			csnumber = k;
			System.out.println("csnumber:" + csnumber);
			System.out.println(hashMap3.get("id" + k));
			System.out.println(hashMap4.get("title" + k));
			response.getWriter().append("<table border='1' id='" + hashMap3.get("id" + k) + "'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th class='idkdxg'>");
			response.getWriter().append("<a onclick='csidyl()'>");
			response.getWriter().append(hashMap3.get("id" + k));
			response.getWriter().append("</a>");
			response.getWriter().append("</th>");
			response.getWriter().append("<th class='bkkdxg'>");
			response.getWriter().append("<a onclick='csidyl()'>");
			response.getWriter().append(hashMap4.get("title" + k));
			response.getWriter().append("</a>");
			response.getWriter().append("</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			k ++;
			}
			rsu.close();
			rsv.close();
			rsr.close();
			rsw.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
	<!--   <span><a href="http://localhost:8089/blog_typelist.jsp" class="fhsyy">返回上一页</a></span>   -->
	<form method="post" name="pasorms" action="blogpage.jsp">
		<input type='hidden' name="csflid">
		<input type='hidden' name="csflids">
	</form>
	<!--  
	<span class="sbwz">鼠标当前在:</span>
	<span id="show" class="szwz"></span>
	-->
	<br><br><br><br><br><br><br><br><br><br>
	<script type="text/javascript">
	var diffiernums = 0;
	function fnGetTable(oEl) {
		try {
			while (null != oEl && oEl.tagName != "TABLE") {
				oEl = oEl.parentElement;
			}
			return oEl;
		} catch (e) {
			return null;
		}
	}
	function pos() {
		try {
			oElement = document.elementFromPoint(event.x, event.y);
			oElement = fnGetTable(oElement);
			if (oElement.tagName == "TABLE")
				//show.innerText = oElement.id;
			    diffiernums = oElement.id;
		} catch (e) {
		}
	}
	function setinputt(csflid,csflids){
		document.pasorms.csflid.value = csflid;
		document.pasorms.csflids.value = csflids;
	    document.pasorms.submit();
	}
	function csidyl(){
		setinputt(diffiernums,"mdzz");
	}
	</script>
</body>
</html>